package com.burgeon.backend.SHOP.controller;


import com.burgeon.backend.SHOP.entity.Comment;
import com.burgeon.backend.SHOP.service.AssessService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("shop/assess")
public class AssessController extends BaseController {
    @Autowired
    AssessService assessService;
    //查看商品评论
    @RequestMapping("goodsdata")
    public ResponseResult<List<Comment>> getGoodsComment(String gid,HttpSession session) throws NullPointerException{
       String token = session.getAttribute("token").toString();
       List<Comment> data = assessService.GetGoodsComment(gid,token);
       return new ResponseResult<List<Comment>>(SUCCESS,data);
    }

    @RequestMapping("create")
    public ResponseResult<Void> createComment(Comment comment,String[] gid, HttpSession session){

        String token = session.getAttribute("token").toString();
        String vip = session.getAttribute("phone").toString();
        if (null==comment.getComment()||"".equals(comment.getComment())){
            comment.setComment("此用户未填写评价内容");
        }
        comment.setVip(vip);
        assessService.createComment(comment,gid,token);
        return new ResponseResult<>(SUCCESS);
    }

}